<?php
function setOpenList ($tbl = "3s1")
{
    switch ($tbl)
    {
        case "3s1" :
            $roundQty = 23;
            break;
        case "3s3" :
            $roundQty = 120;
            break;
        case "3s4" :
            $roundQty = 30;
            break;
        case "5h" :
            $roundQty = 50;
            break;
        default :
            $roundQty = 84;
            break;
    }
    $rs = getdb("select value from k_config where id = 'lotto_auto_{$tbl}' LIMIT 1");
    if (intval($rs->f[0]) == 1)
    {
        return FALSE;
    }
    else
    {
        $rs = getdb("!!SELECT * FROM lotto_{$tbl} WHERE n1>=0 ORDER BY open DESC ,round DESC LIMIT {$roundQty}");
        $buf = "\$aNum = array(\n";
        while (!$rs->eof)
        {
            switch ($tbl)
            {
                case "3s1" :
                    $Numbers = $rs->f['n3'] . "," . $rs->f['n2'] . "," . $rs->f['n1'];
                    $round = date("Ymd", strtotime($rs->f['openbet'])) . "-" . d2($rs->f['round']);
                    break;
                case "3s2" :
                    $Numbers = $rs->f['n5'] . "," . $rs->f['n4'] . "," . $rs->f['n3'] . "," . $rs->f['n2'] . "," . $rs->f['n1'];
                    $round = $rs->f['round'];
                    break;
                case "5h" :
                    $Numbers = d2($rs->f['n1']) . "," . d2($rs->f['n2']) . "," . d2($rs->f['n3']) . "," . d2($rs->f['n4']) . "," . d2($rs->f['n5']);
                    $round = $rs->f['round'];
                    break;
                case "8h" :
                    $Numbers = d2($rs->f['n1']) . "," . d2($rs->f['n2']) . "," . d2($rs->f['n3']) . "," . d2($rs->f['n4']) . "," . d2($rs->f['n5']) . "," . d2($rs->f['n6']) . "," . d2($rs->f['n7']) . "," . d2($rs->f['n8']);
                    $round = $rs->f['round'];
                    break;
            }
            $Numbers = $rs->f['n5'] . "," . $rs->f['n4'] . "," . $rs->f['n3'] . "," . $rs->f['n2'] . "," . $rs->f['n1'];
            $round = date("Ymd", strtotime($rs->f['openbet'])) . "-" . substr($rs->f['round'], 0 - 3);
            $BonusTime = date("Y-m-d H:i", strtotime($rs->f['openbet']));
            $buf .= "array(\"BonusNumberString\",\"{$Numbers}|0|0\",\"BonusTime\",\"{$BonusTime}\",\"IssueNumber\",\"{$round}\"),\n";
            $rs->next();
        }
        if (substr($buf, 0 - 1) == "\n")
        {
            $buf = substr($buf, 0, strlen($buf) - 2) . ");\$reset=1;";
            $tagFile = "open_{$tbl}.txt";
            if ($fp = fopen($tagFile, "w"))
            {
                fwrite($fp, $buf);
                fpassthru($fp);
            }
        }
    }
}

?>